package cn.tedu.hotel.serve.controller;

import cn.tedu.hotel.serve.pojo.entity.secondary.Banner;
import cn.tedu.hotel.serve.service.ISecondaryBannerService;
import cn.tedu.hotel.serve.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/secondaryBanner")
@Api(tags = "07. 轮播图管理模块")
public class SecondaryBannerController {
    @Autowired
    ISecondaryBannerService secondaryBannerService;

    @PostMapping("/insert")
    @ApiOperation("添加轮播图")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> insert(String url) {
        log.debug("开始处理【添加轮播图】的请求，参数：{}", url);
        secondaryBannerService.insert(url);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("根据ID删除轮播图")
    @ApiOperationSupport(order = 200)
    public JsonResult<Void> deleteById(@PathVariable Long id) {
        log.debug("开始处理【根据ID删除轮播图】的请求，参数：{}", id);
        secondaryBannerService.deleteById(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改轮播图详情")
    @ApiOperationSupport(order = 300)
    public JsonResult<Void> updateInfoById(@Valid Banner banner) {
        log.debug("开始处理【修改轮播图详情】的请求，新数据：{}",banner);
        secondaryBannerService.update(banner);
        return JsonResult.ok();
    }

    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("根据ID查询轮播图详情")
    @ApiOperationSupport(order = 410)
    public JsonResult<Banner> selectById(@PathVariable Long id) {
        log.debug("开始处理【根据ID查询轮播图详情】的请求，参数：{}", id);
        Banner queryResult = secondaryBannerService.selectById(id);
        return JsonResult.ok(queryResult);
    }

    @GetMapping("")
    @ApiOperation("查询轮播图列表")
    @ApiOperationSupport(order = 420)
    public JsonResult<List<Banner>> select() {
        log.debug("开始处理【查询轮播图列表】的请求，无参数");
        List<Banner> list = secondaryBannerService.select();
        return JsonResult.ok(list);
    }
}
